///////////////////////////////////////////////////
// Election Administration Polarization
// Joint Policy RD Table
///////////////////////////////////////////////////

gl path "~/Library/CloudStorage/GoogleDrive-danmckinleythompson@gmail.com/My Drive/ElecAdminPolarization/How_Partisan_Is_Local_Election_Admin_Replication"

* Bring in the turnout and registration analysis data
use "$path/analysis_data/rd_reg_turnout_analysis_data.dta", clear

// Polling places
rdrobust r_eavs_polling_places_per1k rv, vce(cluster election_id)
rdtab r_eavs_polling_places_per1k treat rv election_id, est_command("rdrobust") new("B")
sum eavs_polling_places_per1k
local m1 = r(mean)

// Provisionals
rdrobust r_prov_rate rv, vce(cluster election_id)
rdtab r_prov_rate treat rv election_id, est_command("rdrobust") old("B")
sum prov_rate
local m2 = r(mean)

// Provisionals rejected
rdrobust r_prov_rejection_rate rv, vce(cluster election_id)
rdtab r_prov_rejection_rate treat rv election_id, est_command("rdrobust") old("B")
sum prov_rejection_rate
local m3 = r(mean)

// Absentee rejection rate
rdrobust r_eavs_absentee_rej_rate rv, vce(cluster election_id)
rdtab r_eavs_absentee_rej_rate treat rv election_id, est_command("rdrobust") old("B")
sum eavs_absentee_rej_rate
local m4 = r(mean)

// Registration
rdrobust r_registered_pc rv, vce(cluster election_id)
rdtab r_registered_pc treat rv election_id, est_command("rdrobust") old("B")
sum registered_pc
local m5 = r(mean)

// Registration removal rate
rdrobust r_eavs_reg_removal_rate rv, vce(cluster election_id)
rdtab r_eavs_reg_removal_rate treat rv election_id, est_command("rdrobust") old("B")
sum eavs_reg_removal_rate
local m6 = r(mean)

// Dem registration share
rdrobust r_reg_dem_share rv, vce(cluster election_id)
rdtab r_reg_dem_share treat rv election_id, est_command("rdrobust") old("B")
sum reg_dem_share
local m7 = r(mean)

// Wait times r_wait_over30
rdrobust r_wait_over30 rv, vce(cluster election_id)
rdtab r_wait_over30 treat rv election_id, est_command("rdrobust") old("B")
sum wait_over30
local m8 = r(mean)


qui {
* Build the memo/paper table
cap log close
set linesize 255
log using "$path/output/rd_table_policy.tex", text replace
noi di "\begin{table}[t]"
noi di "\centering"
noi di "\caption{\textbf{Effect of Democratic Election Officials on Policies and More Proximate Outcomes.}"
noi di "\label{tab:rd_table_policy}}"
noi di "\begin{tabular}{lcccccccc}"
noi di "\toprule \toprule"
noi di " & Polling 	& Prov		& Prov		& Absentee	& Reg	& Reg		& Dem Reg 	& Wait  \\"
noi di " & Places	& Share		& Rejection	& Rejection	& Rate	& Removal	& Share		& Share \\"
noi di " & (1)		& (2)		& (3)		& (4)		& (5)	& (6)		& (7)		& (8)   \\"
noi di "\midrule"
noi di "Dem Elec Official & " %4.3f B[1,1] " & " %4.3f B[1,2] " & " %4.3f B[1,3] " & " %4.3f B[1,4] " "
noi di 		" & " %4.3f B[1,5] " & " %4.3f B[1,6] " & " %4.3f B[1,7] " & " %4.3f B[1,8] "\\"
noi di " & (" %4.3f B[2,1] ") & (" %4.3f B[2,2] ") & (" %4.3f B[2,3] ") & (" %4.3f B[2,4] ") "
noi di 		" & (" %4.3f B[2,5] ") & (" %4.3f B[2,6] ") & (" %4.3f B[2,7] ") & (" %4.3f B[2,8] ") \\[2mm]"
noi di "\midrule"
noi di "N & " %4.0f B[3,1] " & " %4.0f B[3,2] " & " %4.0f B[3,3] " & " %4.0f B[3,4] " "
noi di 	" & " %4.0f B[3,5] " & " %4.0f B[3,6] " & " %4.0f B[3,7] " & " %4.0f B[3,8] " \\ "
noi di "Clusters & " %4.0f B[4,1] " & " %4.0f B[4,2] " & " %4.0f B[4,3] " & " %4.0f B[4,4] " "
noi di 	" & " %4.0f B[4,5] " & " %4.0f B[4,6] " & " %4.0f B[4,7] " & " %4.0f B[4,8] " \\ "
noi di "Outcome Mean & " %4.3f `m1' " & " %4.3f `m2' " & " %4.3f `m3' " & " %4.3f `m4' " "
noi di 	" & " %4.3f `m5' " & " %4.3f `m6' " & " %4.3f `m7' " & " %4.3f `m8' " \\ "
noi di "Bandwidth & " %4.2f B[5,1] " & " %4.2f B[5,2] " & " %4.2f B[5,3] " & " %4.2f B[5,4] " "
noi di 	" & " %4.2f B[5,5] " & " %4.2f B[5,6] " & " %4.2f B[5,7] " & " %4.2f B[5,8] " \\ "
noi di "BW Selection & CCT & CCT & CCT & CCT & CCT & CCT & CCT & CCT \\"
noi di "Kernel & Tri & Tri & Tri & Tri & Tri & Tri & Tri & Tri \\"
noi di "\bottomrule \bottomrule"
noi di "\multicolumn{9}{p{1.1\textwidth}}{\footnotesize Robust standard errors clustered by clerk election in parentheses. "
noi di "The outcome is first regressed on a state- and year-specific lag using all counties including those for which clerk election "
noi di "results are not available. The regression discontinuity is estimated using the residuals from that regression. "
noi di "The bandwidth row reports the number of maximum clerk win margin allowed for inclusion in each specificaiton. "
noi di "CCT refers to \cite{calonico2014robust} bandwidth selection procedure."
noi di "Tri refers to a triangular kernel.}"
noi di "\end{tabular}"
noi di "\end{table}"
log off
}

